package 网络编程.Text;

import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.Socket;
import java.util.Scanner;

public class TCPText3 {
    public static void main(String[] args) throws IOException {
        //客户端:发送一条数据,接收服务端反馈的信息,打印
        //服务器:接收数据并打印,在给客户端反馈信息

        Socket socket=new Socket("127.0.0.1",10005);
        OutputStream outputStream = socket.getOutputStream();
        Scanner scanner=new Scanner(System.in);
        String next = scanner.next();
        outputStream.write(next.getBytes());
        //结束标记,跳出通道,继续执行下面的语句
        socket.shutdownOutput();

        //接收数据的反馈
        InputStreamReader isr=new InputStreamReader(socket.getInputStream());
        int a;
        while ((a=isr.read())!=-1){
            System.out.print((char) a);
        }
        isr.close();
        socket.close();
    }
}
